/**
 * 
 */
package com.thon.dao.project.impl;


import org.springframework.stereotype.Repository;

import com.thon.dao.project.ProjectShareDao;
import com.thon.dao.util.AbstractDao;
import com.thon.dao.util.Page;
import com.thon.entity.project.ProjectShare;

/**
 * @file ProjectShareDaoImpl.java
 * @author Zemo
 * @mail zemochen@gmail.com
 * @data 2013年10月11日 上午11:32:53
 * @description: TODO
 */
@Repository
public class ProjectShareDaoImpl extends AbstractDao<ProjectShare> implements ProjectShareDao{
	
	public ProjectShareDaoImpl(){
		super(ProjectShare.class);
	}

	@Override
	public Long countShare(int projectId) {

		String queryString = "SELECT COUNT(*) FROM ProjectShare ps WHERE ps.project.id = ?";
		return count(queryString, projectId);
	}
	

	public Long countPreferentialShare(int preferentialId) {

		String queryString = "SELECT COUNT(*) FROM ProjectShare ps WHERE ps.preferential.id = ?";
		return count(queryString, preferentialId);
	}
	
	
	@Override
	public Page<ProjectShare> findProjectShareByUser(Integer userId,Integer method,
			Page<ProjectShare> page) {
		StringBuffer queryString = new StringBuffer();
		queryString.append("FROM ProjectShare ps WHERE ps.userId=?");
		if(method.equals(2))
			queryString.append(" AND ps.project IS null");
		else	if(method.equals(1))
				queryString.append(" AND ps.preferential IS null");			
		return findPage(page, queryString.toString(), userId);
	}

	
}
